"""
获取指定文件夹的所有文件的 PATH
"""
import os
import random
Dir = r"D:\Code\Python\Shutdown"


def file_name(Dir):
    r""" 这段代码只能获取.jpg，.png不行（or的优先级高与is）
    return 一个字符串 > 随机一张图片的绝对路径
     """
    c = []
    a = os.walk(Dir)
    for root, dirs, files in a:
        for file in files:
            path = os.path.join(root, file)
            # print(path[-4:])
            if (path[-4:] == ".jpg") or (path[-4:] == ".png") or (path[-4:] == ".tif") or (path[-4:] == ".gif"):
                c.append(path)
    return c[random.randint(0, len(c)-1)]


print(file_name(Dir))
